/*
 * Copyright (c) 2014 The Native Client Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#ifndef IRT_SOCKET_H
#define IRT_SOCKET_H

#include <stdarg.h>
#include <stddef.h>
#include <sys/types.h>

#if defined(__cplusplus)
extern "C" {
#endif

/*
 * The "irt-dev-socket" provides socket functionality excluding, select
 * which is on its own API.
 */

struct nacl_abi_sockaddr;

#define NACL_IRT_DEV_SOCKET_v0_1 "nacl-irt-dev-socket-0.1"
struct nacl_irt_dev_socket {
  int (*accept)(int sockfd, struct nacl_abi_sockaddr* addr, size_t addrlen,
                int* newfd);
  int (*bind)(int sockfd, const struct nacl_abi_sockaddr* local,
              size_t addrlen);
  int (*connect)(int sockfd, const struct nacl_abi_sockaddr* dst,
                 size_t addrlen, int* newfd);
  int (*getpeername)(int sockfd, struct nacl_abi_sockaddr* addr,
                     size_t* addrlen);
  int (*getsockname)(int sockfd, struct nacl_abi_sockaddr* addr,
                     size_t* addrlen);
  int (*getsockopt)(int sockfd, int level, int optname, void* optval,
                    size_t* optlen);
  int (*listen)(int sockfd, int backlog);
  int (*pipe)(int fds[2]);
  int (*recvfrom)(int sockfd, void* buffer, size_t len, int flags,
                  struct nacl_abi_sockaddr* src, size_t* addrlen);
  int (*sendto)(int sockfd, const void* buffer, size_t len, int flags,
                const struct nacl_abi_sockaddr* src, size_t addrlen);
  int (*setsockopt)(int sockfd, int level, int optname, const void* optval,
                    size_t optlen);
  int (*socket)(int domain, int type, int protocol, int* newfd);
  int (*socketpair)(int domain, int type, int protocol, int sv[2]);
  int (*shutdown)(int sockfd, int flags);
};

#if defined(__cplusplus)
}
#endif

#endif /* IRT_SOCKET_H */
